//
//  AutomaticLayoutCollectionViewController.swift
//  SwiftTest
//
//  Created by 北京 on 2020/12/9.
//  Copyright © 2020 QiKai. All rights reserved.
//

import UIKit



class AutomaticLayoutCollectionViewController:
    UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
    
    
    let cellid:String = "AutomaticCollectionCell"
    
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.data.count;
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        

        let mov:AutomaticCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier:cellid, for: indexPath) as! AutomaticCollectionCell
        mov.data = self.data[indexPath.row];
        
        return mov;
        
    }
    

    var collectionTopView : UICollectionView!
    let data:[String] = ["阿道夫达到设计法核算的减肥哈三等奖发电机房哈积分","很骄傲和房间爱对方建安费哈剪短发记得发就发哈尽快答复哈电机开发哈尽快答复哈金凤凰大连房价哈金凤凰大家啊发哈","骄傲的房间爱打架复活卡京东方had房间爱空间发空间发就发痕迹啊骄傲的加法减法将发动机开发建安费建安费很骄傲答复哈监督法简单快乐风家得福建安费觉得埃及答复哈剪短发哈借款方哈京东方哈酒砥砺奋进卡迪夫"];
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        let layout = UICollectionViewFlowLayout.init()
//        layout.itemSize = CGSize(width: 100, height: 40)//cell高度不能比collectionView高度高
        layout.estimatedItemSize = CGSize(width: kScreenWidth, height: 30)
 
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .vertical
        layout.sectionInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0)
        
        collectionTopView = UICollectionView.init(frame: CGRect.null, collectionViewLayout: layout)
        collectionTopView.backgroundColor = .green
        self.view.addSubview(collectionTopView)
        collectionTopView.register(AutomaticCollectionCell.self, forCellWithReuseIdentifier: cellid)
        collectionTopView.delegate = self
        collectionTopView.dataSource = self
        collectionTopView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        self.collectionTopView.reloadData()
        
    }
    
    
    
    
    
}
